package br.upe.dsc.caeto.core;

import br.upe.dsc.caeto.core.project.Project;
import br.upe.dsc.caeto.core.project.ProjectRegister;
import br.upe.dsc.caeto.core.project.ProjectRepositoryXml;

import java.util.Iterator;

public class CaetoManager {
	private IRegister<Project> projectRegister;
	private static CaetoManager singleton;

	private CaetoManager() {
		this.projectRegister = new ProjectRegister(new ProjectRepositoryXml());
	}

	//Only one instance of this class can be instanciated
	public static CaetoManager getInstance() {
		if (singleton == null) {
			singleton = new CaetoManager();
		}
		return singleton;
	}

	//Project
	public void add(Project project) throws InvalidElementException {
		this.projectRegister.add(project);
	}

	public void remove(Project project) throws ElementNotFoundException {
		this.projectRegister.remove(project);
	}
	
	public void update(Project project) throws ElementNotFoundException,
		InvalidElementException {
		
		this.projectRegister.update(project);
	}
	
	public Project search(String name) throws ElementNotFoundException {
		return this.projectRegister.search(name);
	}
	
	public boolean isProject(String name) {
		return this.projectRegister.isElement(name);
	}
	
	public Iterable getProjects() {
		return this.projectRegister.getElements();
	}
}
